﻿/* 9. We are given 5 integer numbers. Write a program that checks if the sum of some subset of them is 0. 
 * Example: 3, -2, 1, 1, 8 --> 1+1-2=0. */

using System;
using System.Collections.Generic;

public class SubsetWithZeroSum
{
    public static uint numbers;
    public static List<decimal> listOfNumbers = new List<decimal>();

    public static void Main()
    {
        DataInput();
        Console.WriteLine("Is there zero sum? : {0}", IsThereZeroSum(listOfNumbers));
    }

    public static string IsThereZeroSum(List<decimal> list)
    {
        int end = (int)Math.Pow(2, numbers);
        decimal zeroSum;

        for (int subset = 1; subset < end; subset++)
        {
            zeroSum = 0M;
            for (int position = 0; position < numbers; position++)
                if (((1 << position) | subset) == subset)
                    zeroSum += listOfNumbers[position];

            if (zeroSum == 0)
                return "Yes!";
        }

        return "No!";
    }

    public static void DataInput()
    {
        decimal member;

        do
        {
            Console.Clear();
            Console.Write("How many numbers (in range [1,30]) including the set? : ");
            if ((uint.TryParse(Console.ReadLine(), out numbers)) && (numbers > 0) && (numbers < 31))
                break;
        } while (true);

        for (int number = 1; number <= numbers; number++)
        {
            do
            {
                Console.Clear();
                Console.WriteLine("All Number : {0}", numbers);
                for (int entered = 1; entered < number; entered++)
                    Console.WriteLine("number {0} = {1}", entered, listOfNumbers[entered - 1]);

                Console.Write("number {0} = ", number);
                if (decimal.TryParse(Console.ReadLine(), out member))
                {
                    listOfNumbers.Add(member);
                    break;
                }
            } while (true);
        }
    }
}